<?php

namespace App\Models\CacheModel\privatearea;

use App\Models\Api\BaseCache;

class PrivateAreaShortLinkJump extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.private_area_short_link_jump';

    protected $cacheModel = 'privatearea.short_link';

    public function SaveData(array $data)
    {
        try
        {
            $id = $this->insertGetId($data);

            return (int)$id;
        }
        catch (\Exception $e)
        {
            \think\Log::write(__CLASS__ . ' => ' . __FUNCTION__ . '()异常：' . $e->getMessage() . '失败信息：' . $e->getFile() . ':' . $e->getLine(), 'error', true);
            return 0;
        }
    }

    /**
     * @param array $ids
     * @param array|null $type
     * @param string $sortType
     * @return array
     */
    public function getInfoByIdsInData($ids, $type, $sortType)
    {
        if (count($ids) > 1)
        {
            $where = ['hash' => ['in', $ids]];
        } else
        {
            $where = ['hash' => $ids[0]];
        }
        $field = 'id,hash,link,create_time';
        try
        {
            $data = $this->field($field)->where($where)->column($field, 'hash');
        }
        catch (\Exception $e)
        {
            $data = [];
        }
        $a= $this->getLastSql();
        return $data;
    }

    public function batchGetInfoByIds($cids, $field = [])
    {
        $resData = parent::batchGetInfoByIds($cids, $field);
        foreach ($resData as $orderId => $orderItemData)
        {
            $resData[$orderId] = arrayKeyData2int($orderItemData, ['id', 'create_time']);
        }

        return $resData;
    }
}
